package com.huawei.esdk.uc.device.u19.ctc;

import java.util.List;
import org.apache.log4j.Logger;
import com.huawei.ecs.bin.service.AddConf;
import com.huawei.ecs.bin.service.AddConfAck;
import com.huawei.ecs.bin.service.DelConf;
import com.huawei.ecs.bin.service.DelConfAck;
import com.huawei.ecs.bin.service.SetConf;
import com.huawei.ecs.bin.service.SetConfAck;
import com.huawei.ecs.bin.service.ShowConf;
import com.huawei.ecs.bin.service.ShowConfAck;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.uc.device.AbstractU19Capability;
import com.huawei.esdk.uc.device.u19.ICTCU19Capability;
import com.huawei.esdk.uc.device.u19.ctc.convert.CTCCapabilityConvert;
import com.huawei.esdk.uc.domain.model.Conference;

public class CTCU19CapabilityImpl extends AbstractU19Capability implements ICTCU19Capability
{
    private static final Logger LOGGER = Logger.getLogger(CTCU19CapabilityImpl.class);
    
    private CTCCapabilityConvert ctcCapabilityConvert = new CTCCapabilityConvert();
    
    @Override
    public SDKResult<String> createConf(Conference confParam)
    {
        LOGGER.debug("createConf start");
        SDKResult<String> sdkResult = null;
        
        AddConf addConf = ctcCapabilityConvert.createConfModal2South(confParam);
         
        AddConfAck response = getUcU19Provider().sendMsg(addConf, confParam.getGwIp(), AddConfAck.class);
        
        sdkResult = ctcCapabilityConvert.createConfSouth2Modal(response);
        
        LOGGER.debug("createConf end");
        return sdkResult;
    }
    
    @Override
    public SDKResult<String> modifyConf(Conference confInfo)
    {
        LOGGER.debug("modifyConf start");
        SDKResult<String> sdkResult = null;
        
        SetConf addOConf = ctcCapabilityConvert.modifyConfModal2South(confInfo);
        
        SetConfAck response = getUcU19Provider().sendMsg(addOConf, confInfo.getGwIp(), SetConfAck.class);
        
        sdkResult = ctcCapabilityConvert.modifyConfSouth2Modal(response);
        LOGGER.debug("modifyConf end");
        return sdkResult;
    }
    
    @Override
    public SDKResult<Conference> endConf(String userId, String gwIp, List<Integer> confRooms)
    {
        LOGGER.debug("endConf start");
        SDKResult<Conference> sdkResult = new SDKResult<Conference>();
        
        DelConf delConf = new DelConf();
        delConf.confNos_ = confRooms;
        
        DelConfAck response = getUcU19Provider().sendMsg(delConf, gwIp, DelConfAck.class);
        
        sdkResult.setErrCode(response.retCode_);
        sdkResult.setDescription(response.getCmdCode().name() + " " + response.getCmdCode().value());
        
        LOGGER.debug("endConf end");
        return sdkResult;
    }
    
    @Override
    public SDKResult<List<Conference>> queryConf(String userId, String gwIp, String subPbxNo, String confRoom)
    {
        LOGGER.debug("queryConf start");
        SDKResult<List<Conference>> sdkResult = null;
        ShowConf showConf = new ShowConf();
        
        ShowConfAck response = getUcU19Provider().sendMsg(showConf, gwIp, ShowConfAck.class);
        
        sdkResult = ctcCapabilityConvert.queryConfSouth2Modal(response);
        LOGGER.debug("queryConf end");
        return sdkResult;
    }
    
}